//
//  WZC_ViewController.swift
//  XMYouPin
//
//  Created by 王宗成 on 2019/7/2.
//  Copyright © 2019 王宗成. All rights reserved.
//

import UIKit

class WZC_ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        
        if (self.navigationController?.responds(to: #selector(getter: UINavigationController.interactivePopGestureRecognizer)))! {
            self.navigationController?.interactivePopGestureRecognizer?.isEnabled = true;
            self.navigationController?.interactivePopGestureRecognizer!.delegate = nil;
        }
        
        setLeftButtonItemWithImg("mjyp_right_arrow_brown")
        // Do any additional setup after loading the view.
    }
    
}

extension WZC_ViewController
{
    
    func setLeftButtonItemWithImg(_ imgName:String) -> Void {
        
        let leftButton:UIButton = UIButton(type: .custom)
        
        leftButton.setImage(IMAGE(imgName), for: .normal)
        
        leftButton.sizeToFit()
        
        leftButton.contentEdgeInsets = UIEdgeInsets(top: 2, left: -10, bottom: 0, right: 0)
        
        let leftItem:UIBarButtonItem = UIBarButtonItem(customView: leftButton)

        self.navigationItem.leftBarButtonItem = leftItem
        
        leftButton.addTarget(self, action: #selector(navBarClickLeftAction), for: .touchUpInside)
    }
    
    func setRightButtonItemWithImg(_ imgName:String) -> Void {
        
        let leftButton:UIButton = UIButton(type: .custom)
      
        leftButton.setImage(IMAGE(imgName), for: .normal)
        
        leftButton.sizeToFit()
        
        leftButton.contentEdgeInsets = UIEdgeInsets(top: 2, left: -10, bottom: 0, right: 0)
        
        let leftItem:UIBarButtonItem = UIBarButtonItem(customView: leftButton)
        
        self.navigationItem.rightBarButtonItem = leftItem
        
        leftButton.addTarget(self, action: #selector(navBarClickRightAction), for: .touchUpInside)
    }
    
    func setRightButtonItemWithTitle(_ title:String) -> Void {
        
        let leftButton:UIButton = UIButton(type: .custom)
        
        leftButton.setTitle(title, for: .normal)
        
        leftButton.sizeToFit()
        
        leftButton.contentEdgeInsets = UIEdgeInsets(top: 2, left: -10, bottom: 0, right: 0)
        
        let leftItem:UIBarButtonItem = UIBarButtonItem(customView: leftButton)
        
        self.navigationItem.rightBarButtonItem = leftItem
        
        leftButton.addTarget(self, action: #selector(navBarClickRightAction), for: .touchUpInside)
    }
    
    @objc func navBarClickRightAction() -> Void {
        
        
    }
    
    @objc func navBarClickLeftAction() -> Void {
        
        self.navigationController?.popViewController(animated: true)
    }
}
